package com.baizhi.service.impl;

import com.baizhi.dao.AnimalDao;
import com.baizhi.Animal;
import com.baizhi.service.AnimalService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnimalServiceImpl implements AnimalService {
    @Autowired
    private AnimalDao ad;
    @Override
    public PageInfo<Animal> selectByPage(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Animal> animals = ad.selectList(null);
        return new PageInfo<>(animals);
    }

    @Override
    public void delete(int id) {
         ad.deleteById(id);
    }

    @Override
    public void insert(Animal a) {
        ad.insert(a);
    }

    @Override
    public Animal seleteByID(int id) {
        return ad.selectById(id);
    }

    @Override
    public void update(Animal a, int id) {
        QueryWrapper<Animal> qw=new QueryWrapper();
        qw.eq("id",id);
        ad.update(a,qw);
    }
}
